package com.hxkj.service.impl;

import com.hxkj.client.service.UserBlacklistServiceClient;
import com.hxkj.domain.po.UserBlacklist;
import com.hxkj.service.UserBlacklistService;
import com.platform.common.domain.exception.CustomMessageException;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class UserBlacklistServiceImpl implements UserBlacklistService{

    @Autowired
    private UserBlacklistServiceClient ubClient;

    @Override
    public void addBlacklist(UserBlacklist userBlacklist) throws Exception {
        if(StringUtils.isBlank(userBlacklist.getUserId())){
            throw new CustomMessageException("用户编号不能为空");
        }
        if(StringUtils.isBlank(userBlacklist.getBlackerUserName())){
            throw new CustomMessageException("要加入黑名单的用户名不能为空");
        }
        ResultMessageStruct result = ubClient.addBlacklist(userBlacklist);
        if(result.getCode() != 200){
            throw new CustomMessageException(result.getMessage());
        }
    }

    @Override
    public void removeBlacklist(UserBlacklist userBlacklist) throws Exception {
        if(userBlacklist.getId() == null){
            throw new CustomMessageException("黑名单编号不能为空!");
        }
        ResultMessageStruct result = ubClient.removeBlacklist(userBlacklist);
        if(result.getCode() != 200){
            throw new CustomMessageException(result.getMessage());
        }
    }

    @Override
    public List<UserBlacklist> getList(UserBlacklist userBlacklist) throws Exception {
        if(StringUtils.isBlank(userBlacklist.getUserId())){
            throw new CustomMessageException("用户编号不能为空！");
        }
        ResultDataStruct<List<UserBlacklist>> result = ubClient.getList(userBlacklist);
        if(result.getCode() != 200){
            throw new CustomMessageException(result.getMessage());
        }
        return result.getData();
    }
}
